package com.project2.controller;

import com.github.pagehelper.PageHelper;
import com.project2.bean.ResultVo;
import com.project2.bean.vo.WxSearchIndexVo;
import com.project2.service.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: MH
 * @Date: 2022-08-14 21:04
 * @Description: 前台搜索业务
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {
    @Autowired
    WxSearchService wxSearchService;

    /**
    *@Author: MH
    *@date: 2022/8/14 22:38
    *@Description:搜索点击回车键后显示的信息
    */
    @RequestMapping("index")
    public ResultVo showSearchKeywordInfo(HttpServletRequest request){
        WxSearchIndexVo wxSearchIndexVo = wxSearchService.showSearchKeywordInfo(request);
        return ResultVo.ok(wxSearchIndexVo);
    }

    /**
    *@Author: MH
    *@date: 2022/8/14 22:41
    *@Description:清除所有搜索历史
    */
    @RequestMapping("clearhistory")
    public ResultVo deleteSearchHistory(){
        wxSearchService.deleteSearchHistory();
        return ResultVo.ok();
    }

    /**
    *@Author: MH
    *@date: 2022/8/14 22:42
    *@Description:搜索关键字提示
    */
    @RequestMapping("helper")
    public ResultVo searchKeywordHelper(String keyword, HttpServletRequest request){
        List<String> keyWordList = wxSearchService.searchKeywordHelper(keyword,request);
        return ResultVo.ok(keyWordList);
    }
}
